/**
 *博尔信基础开发平台
 *<br> 版权声明：厦门博尔信软件有限公司版权所有,违者必究
 *<br> Copyright:  Copyright (c) 2012
 *<br> Company:pearlsoft
 *<br> @author 蒋勇华
 *<br> 2012-5-7
 *<br> @version 1.0
 *————————————————————————————————————
 *修改记录
 *    修改者：
 *    修改时间：
 *    修改原因：
 *——————————————————————————————————————
 */
package com.pearlsoft.webapp.sysmgr.org;

import org.apache.commons.lang.StringUtils;

import com.pearlsoft.webapp.core.annotation.DataSetHandlerComponent;
import com.pearlsoft.webapp.core.dataset.DataSet;
import com.pearlsoft.webapp.core.dataset.Record;
import com.pearlsoft.webapp.core.dataset.Result;
import com.pearlsoft.webapp.core.web.basehandler.AbsDataSetHandler;
import com.pearlsoft.webapp.sysmgr.org.service.OrgService;

/**
 *描述： 
 *
 * 
 */
@DataSetHandlerComponent(name = "OrgDataSetHandler")
public class OrgDataSetHandler extends AbsDataSetHandler{

	public void handler(DataSet ds, Result result) throws Exception {
		
	}

	public void orgUp(DataSet ds, Result result) throws Exception {
		String orgId=	ds.getValue("orgId").toString();
		OrgService orgService = this.getBean("orgService",OrgService.class);
		orgService.orgUp(orgId);
	}
	
	public void orgDown(DataSet ds, Result result) throws Exception {
		String orgId=	ds.getValue("orgId").toString();
		OrgService orgService = this.getBean("orgService",OrgService.class);
		orgService.orgDown(orgId);
	}

	@Override
	public void save(DataSet ds, Result result) throws Exception {
		OrgService orgService = this.getBean("orgService",OrgService.class);
		Record record = ds.getCurrentRecord();
		orgService.save(record);
		result.getRecords().add(record);
	}

	@Override
	public void delete(DataSet ds, Result result) throws Exception {
		OrgService orgService = this.getBean("orgService",OrgService.class);
		String orgId = (String) ds.getConditions().get("objId");
		orgService.deleteById(orgId);
	}


	@Override
	public void deleteAll(DataSet ds, Result result) throws Exception {
		OrgService orgService = this.getBean("orgService",OrgService.class);
		String objIds = (String) ds.getConditions().get("objIds");
		String[] ids = objIds.split(",");
		for(String id:ids){
			if( !StringUtils.isBlank(id)){
				orgService.deleteById(id);
			}
		}
	}

}
